<!DOCTYPE html>
<%@ page language="java" import="com.compuvest.web.*,java.text.DecimalFormat" pageEncoding="UTF-8" %>

<%@ taglib uri="/WEB-INF/tld/head.tld" prefix="head" %>

<jsp:useBean id="sb" class="SQLBean" scope="application"/>
<jsp:useBean id="advertShow" class="AdvertShow" scope="application"/>
<jsp:useBean id="basket" class="Basket" scope="session"/>
<%!
    private static final String dotline = "<div class='tfi2'>..........................................................................</div>";
%>
<%
    String thisURL = application.getInitParameter("http");

    DecimalFormat priceForm = new DecimalFormat("$#,##0.00");

    int itemID = advertShow.getInt(request.getParameter("iid"), 0);

    // if from advert
    String accwareCode = request.getParameter("acc");

    Items items = sb.getItem(itemID, accwareCode);
    Item item = new Item();
    if(!items.isEmpty()) {
	item = items.getItems().get(0); // select first item
    }

    session.setAttribute("backItemsPage", application.getInitParameter("http") + "Desc.jsp?iid=" + itemID);
%>
<html>
<head>
<title><%= application.getInitParameter("CompanyName") %></title>
<%@include file="./incl/scripts.txt" %>
</head>
<body>

<div id='cvbody'>

 <head:show />

 <div id='cvcont'>
  <table id='cvmain'>
  <colgroup><col width='200px'/><col width='*'/><col width='160px'/></colgroup>
  <tbody>
   <tr>
    <td id='cvleft' valign="top">

     <div id='leftmenu'></div>

    </td>
    <td id='cvcenter' align="center" valign="top">

<%
    if(items.isEmpty()) {
%>
    <h3>There were no matching result for your query.</h3>
<%
    }
    else {
    // select advert coupon
    String advertImage = basket.getCouponShow(advertShow);
    out.write(advertImage);

    // Navigation
    out.write(new StringBuilder(300).
    append("<div id='cv_nav'>&#8226; ").
    append("<a href='").append(thisURL).append("'>Home</a> &#8226; ").
    append("<a href='").append(thisURL).append("Cats.jsp?cid=").append(item.getCategoryParent()).
    append("'>").append(item.getSubcategoryName()).append("</a> &#8226; ").
    append("<a href='").append(thisURL).append("Items.jsp?cid=").append(item.getCategoryParent()).
    append("&sid=").append(item.getCategoryID()).append("'>").append(item.getCategoryName()).
    append("</a><b>").append(items.getEventTime()).
    append(':').append(java.net.InetAddress.getLocalHost().getHostName()).
    append(':').append(System.getProperty("com.sun.aas.instanceName")).
    append("</b>").
    append("</div>\n").toString());
%>
<fieldset style='width:97%;' class='labl'><%= item.getItemName() %></fieldset>
 <div>&nbsp;</div>

 <table style='width:630px'>
  <tr>

   <td id="imgalery">

    <div class="imgborder"><div id="imgbuf"><div id="imgbox"></div></div></div>

   </td>

   <td width='5%'>&nbsp;</td>

   <td>
<%
    if(item.getMfrLink() != null && item.getMfrLink().length() != 0) {
%>
    <div style='font:bold 9pt Arial;'><a href='http://<%= item.getMfrLink() %>' target='_blank'>Product details at manufacturer's site</a></div><br/>
<%
   }
%>
    <div class='mess2'>
<%
    if(basket.getReseller() && item.getResPrice1() != 0d) {
	StringBuilder rline = new StringBuilder(600);

        rline.append("<div class='prel'><div class='tfi2'>&nbsp;</div>");
        rline.append("<div class='absleft tfi2 onw'>Your Price:</div>");
        rline.append("<div class='absright tfi2 onw'>&nbsp;</div>");
        rline.append("</div>");

	if(item.getResPrice1() != 0d) {
    	    rline.append("<div class='prel'>").append(dotline);
    	    rline.append("<div class='absleft tfi4 onw'>1+</div>");
    	    rline.append("<div class='absright tfi4 onw'>").append(priceForm.format(item.getResPrice1())).append("</div>");
    	    rline.append("</div>");
	}
	if(item.getResQuantity2() != 0 && item.getResPrice2() != 0d) {
    	    rline.append("<div class='prel'>").append(dotline);
    	    rline.append("<div class='absleft tfi4 onw'>").append(item.getResQuantity2() + 1).append("+</div>");
    	    rline.append("<div class='absright tfi4 onw'>").append(priceForm.format(item.getResPrice2())).append("</div>");
    	    rline.append("</div>");
	}
	if(item.getResQuantity3() != 0 && item.getResPrice3() != 0d) {
    	    rline.append("<div class='prel'>").append(dotline);
    	    rline.append("<div class='absleft tfi4 onw'>").append(item.getResQuantity3() + 1).append("+</div>");
    	    rline.append("<div class='absright tfi4 onw'>").append(priceForm.format(item.getResPrice3())).append("</div>");
    	    rline.append("</div>");
	}
        rline.append("<div class='prel'>").append(dotline);
        rline.append("<div class='absleft tfi2 onw'>&nbsp;</div>");
        rline.append("<div class='absright tfi2 onw'>&nbsp;</div>");
        rline.append("</div>");

	out.write(rline.toString());
    }
%>
     <div class='prel'><%= dotline %>
      <div class='absleft tfi2 onw' style='color:red;'><%= items.getPriceMessage(item.getBannerMask()).startsWith("Best") ? items.getPriceMessage(item.getBannerMask()) : " Price" %>:</div>
      <div class='absright tfi2 onw' style='color:red;'><%= priceForm.format(item.getPrice()) %></div>
     </div>
     <div class=prel><%= dotline %>
      <div class='absleft tfi2 onw'>Manufacturer:</div>
      <div class='absright tfi2 onw'><%= item.getMfrName() %></div>
     </div>

     <div class='prel'><%= dotline %>
      <div class='absleft tfi2 onw'>Manufacturer P/N:</div>
      <div class='absright tfi2 onw'><%= item.getMfrNumber() %></div>
     </div>
     <div class='prel'><%= dotline %>
      <div class='absleft tfi2 onw'>CompuVest P/N:</div>
      <div class='absright tfi2 onw'><%= item.getAccwareCode() %></div>
     </div>
     <div style='cursor:pointer;' onclick="location.href='<%= application.getInitParameter("info") %>BeforeOrdering.jsp?op=cond'">
      <div class='prel'><%= dotline %>
       <div class='absleft tfi2 onw'>Condition:</div>
       <div class='absright tfi2 onw' style='color:blue;text-decoration:underline;'><%= item.getCondition() %></div>
      </div>
      <div class='prel'><%= dotline %>
       <div class='absleft tfi2 onw'>Package:</div>
       <div class='absright tfi2 onw' style='color:blue;text-decoration:underline;'><%= item.getPackage() %></div>
      </div>
     </div>
     <div class='prel'><%= dotline %>
      <div class='absleft tfi2 onw'>Stock:</div>
      <div class='absright tfi2 onw'><%= item.getStock() ? "Yes" : Integer.toString(item.getQuantity()) %></div>
     </div>
<% // comming-soon or ships in
    if((item.getBannerMask() & items.COMMINGSOON) != 0) { %>
     <div class='prel'><%= dotline %>
      <div class='absleft tfi2 onw' style='color:red;'>Ships in:</div>
      <div class='absright tfi2 onw' style='color:red;'>2-5 Days</div>
     </div>
<%
    }
%>
     <div class='prel'><%= dotline %>
      <div class='absleft tfi2 onw'>Warranty:</div>
      <div class='absright tfi2 onw'><%= item.getWarrantyDays() %><br/></div>
     </div>
    </div>
<%
    // warranty &&  extended warranty any bit up ?
    if((item.getWarrantyMask() & item.EXTENDED_WARRANTY) != 0) {
	StringBuilder wbuff = new StringBuilder(300);
        wbuff.append("<div style='cursor:pointer;'>");
    	wbuff.append("<div class='wty'>");
    	wbuff.append("<span id='wty' class='tipz'>Extended warranty : </span><img id='wty' class='tipz' src='./img/it/hlp.gif' alt=''/>");
        wbuff.append(item.getExtendedWarrantyOptions(0d, false));
    	wbuff.append("</div>");

	out.write(wbuff.toString());
    }
    // Package Include
    if(item.getPackageInclude() != null && item.getPackageInclude().length() != 0) {
	out.write("<div class='tfi5'>Package Includes: " + item.getPackageInclude() + "</div>");
    }
    // comment
    if(item.getComments() != null && item.getComments().length() != 0) {
        out.write("<div class='tfi5'>Comments: " + item.getComments()  + "</div>");
    }
%>
     <div class='tfi5'>Product may differ from image shown.</div>
     <div style='margin:10px 0 2px 5px;'><a id='<%= item.getItemID() %>' class="drpa" href='javascript:;'>Drop Price Alerts</a></div>
     <br/>
     <a class='btlggr' href='<%= thisURL %>Basket.jsp?iidd=<%= item.getItemID() %>'>Add Item to Cart</a>

     <div style='margin-top:15px;'>
      <iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.compuvest.com%2FDesc.jsp%3Fiid%3D<%= itemID %>&amp;send=false&amp;layout=standard&amp;width=450&amp;show_faces=true&amp;action=like&amp;colorscheme=light&amp;font=verdana&amp;height=80&amp;appId=143622009066419" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:250px; height:100px;" allowTransparency="true"></iframe>
     </div>
   </td>
  </tr>
  <tr>
  <td colspan='3'>
   <div id='imgGallery'></div>
  </td>
  </tr>
 </table>

<div>&nbsp;</div>

<br/>

<div style='width:97%;'>
  <div id="cvTabs">
    <ul>
      <li><a class="tab" href="tb01"><span>Overview</span></a></li>
    </ul>

    <div>
      <div class="panel" id="tb01"></div>
    </div>
  </div>
  <div id='warning'></div>
</div>

<%
    } //if(items.isEmpty())
%>
    </td> <%-- id='cvcenter' --%>
    <td id='cvright' valign="top">

     <div id='advright'></div>

     <div id='advshow'></div>

    </td>
   </tr>
  </tbody>
  </table>
 </div>

 <div id='cvfoot'></div>
</div>

</body>
<script type="text/javascript">
  window.addEvent('domready', function() {
    new LeftMenu({gid:<%= item.getCategoryParent() %>,sid:<%= item.getCategoryID() %>,data:<%= advertShow.getLeftMenu() %>});
    new AdvertShow({data:<%= items.getRelativeItemJSON() %>,cols:1,count:6});

    var ddesc = new Descr('cvTabs',{data:<%= item.getJSONDescription() %>});
    new cvTabs('cvTabs',{newtabs: ddesc.getNewTabs()});
    new ImageGalery('imgbuf');
  });
</script>
</html>
